package com.kun.demo05_threadCommunication;

import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//学习线程池
public class TestPool {

    @Test
    public void testPool() {

        //1. 通过Executors工厂类来创建线程池
        ExecutorService pool = Executors.newFixedThreadPool(4);
        //2. 创建多个线程
        pool.execute(new MyThread());
        pool.execute(new MyThread());
        pool.execute(new MyThread());
        pool.execute(new MyThread());
        //3. 关闭线程池
        pool.shutdown();

    }


    class MyThread implements Runnable {
        @Override
        public void run() {
            System.out.println("MyThread run--"+Thread.currentThread().getName());
        }
    }



}
